package eight.test_8_18;

import java.util.Scanner;

public class Main {
    public static int k = 1;
    public static int count;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }
        dfs(0,0,arr);
        System.out.println(count);
    }
    public static void dfs(int x,int y,int[][] arr) {
        if( x < 0 || x >= arr.length || y < 0 || y >= arr[0].length || arr[x][y] == 1 ) {
            if(k == 1) {
                dfs(x+1,y,arr);
                k = 2;
            } else if(k == 2) {
                dfs(x,y - 1,arr);
                k = 3;
            } else if(k == 3) {
                dfs(x - 1,y,arr);
                k = 4;
            } else {
                dfs(x,y + 1,arr);
                k = 1;
            }
            return;
        }
        if(arr[x][y] == 0) {
            count++;
            arr[x][y] = -1;
            if(k == 1) {
                dfs(x,y + 1,arr);
            } else if(k == 2) {
                dfs(x + 1,y ,arr);
            } else if(k == 3) {
                dfs(x ,y - 1,arr);
            } else {
                dfs(x - 1,y,arr);
            }
        }
        if(arr[x][y] == -1) {
            return;
        }
    }
}
